package com.example.app2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.ComponentName;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Log.d("tang", "Activity onCreate: ");
        findViewById(R.id.btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //方法一：将
                //Intent intent = new Intent(MainActivity.this,TestActivity.class);

                Intent intent = new Intent(MainActivity.this,TestActivity.class);

                //方法一：
                //                intent.setClass(MainActivity.this, TestActivity.class);
//                方法二：
                ComponentName component = new ComponentName("com.example.app2", "com.example.app2.TestActivity");
                //或是：
//                ComponentName component = new ComponentName(MainActivity.this,TestActivity.class);

                intent.setComponent(component);
                startActivity(intent);


            }
        });
    }
}